﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Dao;
using Core.Entity;
using System.Data;

namespace Core.Business
{
    public class ProgrammingLanguageBus
    {
        private ProgrammingLanguageDao dao;
        public ProgrammingLanguageBus()
        {
            dao = new ProgrammingLanguageDao();
        }

        public bool insert(ProgrammingLanguage programmingLanguage) {
            return dao.insert(programmingLanguage);
        }

        public bool update(ProgrammingLanguage programmingLanguage) {
            return dao.update(programmingLanguage);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public ProgrammingLanguage get(int id) {
            DataTable dt = dao.get(id);
            ProgrammingLanguage programmingLanguage = new ProgrammingLanguage();

            if (dt.Rows.Count > 0)
            {
                programmingLanguage.Id = Convert.ToInt32(dt.Rows[0]["PGL_ID"]);
                programmingLanguage.Name = dt.Rows[0]["PGL_NAME"].ToString();
                programmingLanguage.Desc = dt.Rows[0]["PGL_DESC"].ToString();
            }
            return programmingLanguage;
        }

        public List<ProgrammingLanguage> getAll() {
            DataTable dt = dao.getAll();
            List<ProgrammingLanguage> list = new List<ProgrammingLanguage>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    ProgrammingLanguage programmingLanguage = new ProgrammingLanguage();
                    programmingLanguage.Id = Convert.ToInt32(dr["PGL_ID"]);
                    programmingLanguage.Name = dr["PGL_NAME"].ToString();
                    programmingLanguage.Desc = dr["PGL_DESC"].ToString();

                    list.Add(programmingLanguage);
                }

            }
            return list;
        }
    }
}
